<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        div{padding:10px;margin:10px;border:solid 1px black;}
    </style>
</head>
<body>
    <div class="app">
        <h1>这是 - {{title}}</h1>
        <p>父组件的数据为：{{msg}}</p>

        <Child1 ref="c"></Child1>

        <p ref="myp">这就是父组件中一个普通段落</p>
    </div>
</body>
<template id="child1Temp">
    <div>
        <h3>这是 - {{title}}</h3>
        <p>子组件的数据为：{{msg}}</p>
        <p>这是父组件的msg：{{$parent.msg}}</p>
        <p>这是父组件的fn方法：{{$parent.fn()}}</p>
        <input type="button" value="修改" @click="change" >
    </div>
</template>
<script src="../vue.global.js"></script>
<script>
    const app = Vue.createApp({
        data(){
            return {
                title: "根组件",
                msg:"父组件的数据"
            }
        },
        methods:{
            fn(){
                console.log("这是父组件的fn")
                return "这是父组件的fn"
            }
        },
        mounted() {
            console.log(this.$refs.myp.innerHTML);
            this.$refs.myp.style.background = "red";
            console.log(this.$refs.c);
            console.log(this.$refs.c.msg);
            console.log(this.$refs.c.change);
            this.$refs.c.change();
        },
        components:{
            Child1: {
                data(){
                    return {
                        title:"子组件1",
                        msg: "子组件的数据"
                    }
                },
                template: "#child1Temp",
                created() {
                    console.log(this.$parent.msg);
                    console.log(this.$parent.fn);
                    this.$parent.fn();
                },
                methods:{
                    change(){
                        this.$parent.msg = "hahahaha"
                    }
                }
            }
        }
    })

    app.mount(".app");

</script>
</html>